package com.zdp.netty.handler.in;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class InHandlerCut extends ChannelInboundHandlerAdapter {
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        System.out.println("channelRead 被调用 ... InHandlerCut");
        Integer val = ((ByteBuf)msg).getInt(0);
        if(val != null && val.intValue() == 1) {
            System.out.println("InHandlerCut ,因为传入的信息为1。截断");
        }else{
            // 调用下一个 handler
            ctx.fireChannelRead(msg);
        }
    }
}
